﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KYO.DAL;

public partial class Modules_Mod_Information_InformationComment : ViewControlBase<Comment>
{
    public event EventHandler SubmitClick;

    // For generating random numbers.
    private Random random = new Random();

    private void Page_Load(object sender, System.EventArgs e)
    {
        if (!this.IsPostBack)

            // Create a random code and store it in the Session object.
            this.Session["CaptchaImageText"] = GenerateRandomCode();
    }
    private bool check()
    {
        bool check = true;
     
            // On a postback, check the user input.
            if (this.CodeNumberTextBox.Text == this.Session["CaptchaImageText"].ToString())
            {
                // Display an informational message.
                this.MessageLabel.CssClass = "info";
                this.MessageLabel.Text = "Correct!";
            }
            else
            {
                // Display an error message.
                this.MessageLabel.CssClass = "error";
                this.MessageLabel.Text = "ERROR: Incorrect, try again.";

                // Clear the input and create a new random code.
                this.CodeNumberTextBox.Text = "";
                this.Session["CaptchaImageText"] = GenerateRandomCode();
                check = false;
            }
      
        return check;
    
    }
    //
    // Returns a string of six random digits.
    //
    private string GenerateRandomCode()
    {
        string s = "";
        for (int i = 0; i < 6; i++)
            s = String.Concat(s, this.random.Next(10).ToString());
        return s;
    }
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        if(sender!=null)
        {
            if (check())
            {
                SubmitClick(sender, e);
            }
        }
    }
}
